package patrol.mobile.com.mobilepatrol.adapter;

import android.content.Context;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.dl7.recycler.adapter.BaseQuickAdapter;
import com.dl7.recycler.adapter.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.culvert.CulvertListActivity;
import patrol.mobile.com.mobilepatrol.bean.Handong;

/**
 * Created by long on 2016/8/24.
 * 桥梁巡查列表
 */
public class CulvertTrackListAdapter extends BaseQuickAdapter<Handong> {
    private CulvertListActivity context;
    private List<String> hdcodes = new ArrayList<>();
    // 用来控制CheckBox的选中状况
    List<Handong> data;
    public CulvertTrackListAdapter(Context context, List<Handong> data) {
        super(context, data);
        this.context = (CulvertListActivity) context;
        this.data = data;

    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.item1;
    }

    @Override
    protected void convert(final BaseViewHolder holder, final Handong item) {
        holder.setText(R.id.tv1, item.ks+"-"+item.kj+"m"+item.hdlx);
        holder.setText(R.id.tv2, item.roadcode+"("+item.roadpos+")");

        CheckBox cb = holder.getView(R.id.cb);
        // 根据isSelected来设置checkbox的选中状况
        cb.setChecked(item.isCheck);
        cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b){
                    //添加到list
                    hdcodes.add(item.hdcode);
                    //更新ui
                    context.specialUpdate(0,hdcodes.size(),item.hdcode);
                }else{
                    hdcodes.remove(item.hdcode);
                    context.specialUpdate(1,hdcodes.size(),item.hdcode);

                }

            }
        });
        if (item.isUp){
            holder.setVisible(R.id.iv_up,true);
        }else{
            holder.setVisible(R.id.iv_up,false);
        }
    }
    public List<String> gethdcodes(){
        return hdcodes;
    }
    public void clearAllhdcodes(){
        hdcodes.clear();
    }

}
